<? 
	include("var.php");
	include("../header.php"); //header untuk banner web site
?>
<script language="javascript" type="text/javascript">
	function PromptSearch(){
	var Key = prompt("Masukkan Kata Kunci Anda:");
	
		if(Key){
			//alert("dsds");
		//window.location.href="search.php?show=report_emp&key="+Key"";
			top.location.href="search.php?show=report_emp&key="+ Key +" ";
		}
	}
	
	function DisableField()
	{
		
		if (document.getElementById("cek").checked == true)
		{
		document.forms[0].pendidikan.disabled = false;
		document.forms[0].fungsional.disabled = false;
		document.forms[0].skill.disabled = false;
		document.forms[0].status.disabled = false;
		}
		else
		{
		document.getElementById("pendidikan").disabled = true;
		document.getElementById("fungsional").disabled = true;
		document.forms[0].skill.disabled = true;
		document.forms[0].status.disabled = true;
		}
	}
	
	function cek_all(){
		var count = document.forms['f1'].elements.length;
		for (i=0; i<count; i++) 
		{
			var element = document.forms['f1'].elements[i]; 
			//if (document.form1.check1.checked == true) 
			//{ 
			if (element.type == "checkbox") 
			{ 
				element.checked=true; 
			} 
			//} 
			else 
			{ 
				element.checked=false; 
			}
		}
	}
	
	function not_cek_all(){
		var count = document.forms['f1'].elements.length;
		for (i=0; i<count; i++) 
		{
			var element = document.forms['f1'].elements[i]; 
			//if (document.form1.check1.checked == true) 
			//{ 
			if (element.type == "checkbox") 
			{ 
				element.checked=false; 
			} 
			//} 
			else 
			{ 
				element.checked=true; 
			}
		}
	}

	function Down(){
		document.forms['f1'].submit();
	}
	
	function show_popup(page)
	{
		child = open
		(
			page,
			"",
			"scrollbars=no,width=500,height=400,left=150,top=150"
		);
	}

	function appr_per(Cat,Periode,NIK,No,Ambil,Tunda,JC)
	{
		var ok = confirm("Apakah Anda yakin menyetujui data tersebut ?");
		if(ok == true)
		{
			window.location.href="<?=$PHP_SELF?>?periode="+ Periode +"&tahun=<?=$tahun?>&appr=yes&jenis_cuti="+ JC +"&show="+ Cat +"&nik="+ NIK +"&no="+No+"&ambil="+Ambil+"&tunda="+Tunda+"";
		}
		else
		{
		}
	}

	function appr_CBCK(Cat,No,JC)
	{
		var ok = confirm("Apakah Anda yakin menyetujui data tersebut ?");
		if(ok == true)
		{
			window.location.href="<?=$PHP_SELF?>?appr=yes&jenis_cuti="+ JC +"&show="+ Cat +"&no="+ No +"";
		}
		else
		{
		}
	}
	
	function hapus2(Cat,NIK,No)
	{
		var ok = confirm("Apakah Anda yakin menghapus data tersebut ?");
		if(ok == true)
		{
			window.location.href="delete.php?cat="+ Cat +"&nik="+ NIK +"&no="+No+"";
		}
		else
		{
		}
	}
	
</script>
<?
include("config.php");
include("function.php");
include("header.php");

$page 			= $HTTP_GET_VARS['page']; // get nomor halaman yang dipanggil
$next			= $HTTP_GET_VARS['next']; // get segmen halaman yang dipanggil
$keyword		= $HTTP_GET_VARS['keyword'];
$show			= $HTTP_GET_VARS['show'];
$pendidikan		= $HTTP_GET_VARS['pendidikan'];
$pengalaman		= $HTTP_GET_VARS['pengalaman'];
$skill			= $HTTP_GET_VARS['skill'];
$fungsional		= $HTTP_GET_VARS['fungsional'];
$status			= $HTTP_GET_VARS['status'];
$cat			= $show;
$key			= $HTTP_GET_VARS['key'];
$st				= $HTTP_GET_VARS['st'];
$log_id			= $HTTP_GET_VARS['log_id'];
$divisi			= $HTTP_GET_VARS['divisi'];
$nik			= $HTTP_GET_VARS['nik'];
$no				= $HTTP_GET_VARS['no'];
$jenis_cuti 	= $HTTP_GET_VARS['jenis_cuti'];
$bulan1 		= $HTTP_GET_VARS['bulan1'];
$bulan2 		= $HTTP_GET_VARS['bulan2'];
$tahun1 		= $HTTP_GET_VARS['tahun1'];
$tahun2 		= $HTTP_GET_VARS['tahun2'];
$stat_kar		= $HTTP_GET_VARS['stat_kar'];

$b2				= $HTTP_GET_VARS['b2'];
$b1				= $HTTP_GET_VARS['b1'];
$t2				= $HTTP_GET_VARS['t2'];
$t1				= $HTTP_GET_VARS['t1'];
$filter			= $HTTP_GET_VARS['filter'];

$jenis			= $HTTP_GET_VARS['jenis'];

//$status 		= $HTTP_GET_VARS['status'];

//\////////////////////////////////////////\\
//\	Untuk Pencarian berdasarkan FILTER  //\\/
//\////////////////////////////////////////\\

if($show == "report_emp"){

//echo $pengalaman;
//exit;
	echo"
	<table width=93% class='table_indent2'>
	 <tr>
	  <td colspan=2 class=line_bottom><b>&nbsp;&nbsp;&nbsp;CV ONLINE</b></td>
	 </tr>
	</table>";
	echo"<br>";
	SearchFilter($cat,$conn,$log_id);
	echo"
	Keterangan :<br><span style='background-color:#FFD5D5; border: solid 1px; width:40px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> CV Pegawai sedang digunakan
	<span style='background-color:#f3f6f8; width:40px; border: solid 1px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> CV Pegawai tidak digunakan
	<table width=93% class='table_indent2'>";
	$sqlc = "SELECT A.NIK, B.keterangan,B.jurusan,Jenis,fungsi1,fungsi2,";
	if(!empty($skill)){
		$sqlc .=" program,";
	} //*/

	if(!empty($pengalaman)){
		$sqlc .=" Project, ";
	}

	$sqlc .=" A.Nama FROM VLatestKarir A, CVPendidikan B";
	///*
	if(!empty($skill)){
		$sqlc .=", CVKursus D";
	}

	if(!empty($pengalaman)){
		$sqlc .=", VTrackRecord E ";
	}
	//*/
	$sqlc .= " WHERE A.NIK=B.NIK AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%')";
	// jika fungsional saja
	if(!empty($fungsional)){
		$sqlc .=" AND (A.fungsi1='$fungsional' OR A.fungsi2='$fungsional') ";
	}
	// jika status saja
	if(!empty($status)){
		if($status == "bekerja"){
			$sqlc .=" AND Jenis NOT IN ('U','H') ";			
		}
		//elseif($status == "berhenti"){
		else{
			$sqlc .=" AND Jenis IN ('U','H') ";			
		}
	}
	else{
		$sqlc .=" AND Jenis NOT IN ('U','H') ";			
	}
	
	if(!empty($divisi)){
		$sqlc .= " AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."')";
	}
	
	// jika pendidikan
	if(!empty($pendidikan)){
		$sqlc .=" AND B.Pend_ID='$pendidikan'";			
	}		
	///*
	if(!empty($skill)){
		$sqlc .=" AND A.NIK=D.NIK AND program LIKE '%$skill%'";
	}
	
	if(!empty($pengalaman)){
		$sqlc .=" AND (Project LIKE '%".$pengalaman."%') AND A.NIK=E.NIK";
	}

	$sqlc .= " GROUP BY A.NIK, A.Nama, B.keterangan, B.jurusan,Jenis,fungsi1,fungsi2"; 

	if(!empty($skill)){
		$sqlc .=",program";
	}

	if(!empty($pengalaman)){
		$sqlc .=",Project";
	}
				
	$result	= mssql_query($sqlc,$conn);	
	$total	= mssql_num_rows($result);
	$limit	= 20;
	$pager  = Pager::getPagerData($total, $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;
	
	if($total > 0)
	{	
			$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, 
			A.NIK, B.keterangan,B.jurusan,Jenis,fungsi1,fungsi2,";
			if(!empty($skill)){
				$sql .=" program,";
			} //*/

			if(!empty($pengalaman)){
				$sql .=" Project, ";
			}

			$sql .=" A.Nama FROM VLatestKarir A, CVPendidikan B";
			///*
			if(!empty($skill)){
				$sql .=", CVKursus D";
			}

			if(!empty($pengalaman)){
				$sql .=", VTrackRecord E ";
			}
			//*/
			$sql .= " WHERE A.NIK=B.NIK AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%')";
			// jika fungsional saja
			if(!empty($fungsional)){
				$sql .=" AND (A.fungsi1='$fungsional' OR A.fungsi2='$fungsional') ";
			}
			// jika status saja
			if(!empty($status)){
				if($status == "bekerja"){
					$sql .=" AND Jenis NOT IN ('U','H') ";			
				}
				//elseif($status == "berhenti"){
				else{
					$sql .=" AND Jenis IN ('U','H') ";			
				}
			}
			else{
				$sql .=" AND Jenis NOT IN ('U','H') ";			
			}
			
			if(!empty($divisi)){
				$sql .= " AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."')";
			}
			
			// jika pendidikan
			if(!empty($pendidikan)){
				$sql .=" AND B.Pend_ID='$pendidikan'";			
			}		
			///*
			if(!empty($skill)){
				$sql .=" AND A.NIK=D.NIK AND program LIKE '%$skill%'";
			}
			
			if(!empty($pengalaman)){
				$sql .=" AND (Project LIKE '%".$pengalaman."%') AND A.NIK=E.NIK";
			}

			$sql .= " GROUP BY A.NIK, A.Nama, B.keterangan, B.jurusan,Jenis,fungsi1,fungsi2"; 

			if(!empty($skill)){
				$sql .=",program";
			}

			if(!empty($pengalaman)){
				$sql .=",Project";
			}
					
		$sql .=") SELECT NIK, Nama,fungsi1,fungsi2,Jenis FROM limit WHERE No BETWEEN ".$offset." AND ".($offset+$limit)." GROUP BY NIK, Nama,fungsi1,fungsi2,Jenis";

		PagingFilter($pager,$page,$next,$limit,$keyword,$show,$pendidikan,$fungsional,$skill,$log_id,$status,$divisi);
		echo"
		<div class='table_indent2'>
		<form method='get' name='f1' action='rep_cv_all.php'>
		[ <a href='Javascript:cek_all();'>Checklist Semua</a> | <a href='Javascript:not_cek_all();'>Unchecklist Semua</a> | <b><a href='Javascript:Down();'>Download Checklist </a></b> ]
		</div>
		";
		echo"
		<table width=93% class='table_indent2'>";
		HeadKaryawan2();
		$res = mssql_query($sql,$conn);
		//ShowData2($conn,$sql,$cat);
		while($r=mssql_fetch_array($res)){
		
		//Jan 2007 - Feb 2007
		//0123456789012345678
		// B1 = 0,3
		// T1 = 4,4
		// B2 = 11,3
		// T3 = 15,4

		$QST = mssql_query("select * from s_log_detail_cvonline A, s_log_cvonline B 
where A.log_id=B.log_id and NIK='".$r[NIK]."'",$conn);

		if($QST){
			$RST = mssql_fetch_array($QST);
			// get tanggal tahun
			$B1 = substr($RST[periode],0,3);
			$T1 = substr($RST[periode],4,4);
			$B2 = substr($RST[periode],11,3);
			$T2 = substr($RST[periode],15,4);
						
			switch($B1){
				case "Jan" :
					$bulan1 = 1;
					break;
				case "Feb" :
					$bulan1 = 2;
					break;
				case "Mar" :
					$bulan1 = 3;
					break;
				case "Apr" :
					$bulan1 = 4;
					break;
				case "Mei" :
					$bulan1 = 5;
					break;
				case "Jun" :
					$bulan1 = 6;
					break;
				case "Jul" :
					$bulan1 = 7;
					break;
				case "Ags" :
					$bulan1 = 8;
					break;
				case "Sep" :
					$bulan1 = 9;
					break;
				case "Okt" :
					$bulan1 = 10;
					break;
				case "Nov" :
					$bulan1 = 11;
					break;
				case "Des" :
					$bulan1 = 12;
					break;					
			}

			switch($B2){
				case "Jan" :
					$bulan2 = 1;
					break;
				case "Feb" :
					$bulan2 = 2;
					break;
				case "Mar" :
					$bulan2 = 3;
					break;
				case "Apr" :
					$bulan2 = 4;
					break;
				case "Mei" :
					$bulan2 = 5;
					break;
				case "Jun" :
					$bulan2 = 6;
					break;
				case "Jul" :
					$bulan2 = 7;
					break;
				case "Ags" :
					$bulan2 = 8;
					break;
				case "Sep" :
					$bulan2 = 9;
					break;
				case "Okt" :
					$bulan2 = 10;
					break;
				case "Nov" :
					$bulan2 = 11;
					break;
				case "Des" :
					$bulan2 = 12;
					break;					
			}

			$tm1 	= mktime(0,0,0,$bulan1,0,$T1);
			$tm2 	= mktime(0,0,0,$bulan2,0,$T2);
			$tmnow 	= mktime(0,0,0,date("n"),0,date("Y"));
						
			if($tm1 <= $tmnow && $tm2 >= $tmnow){
				$CLSS = " style='background-color: #FFD5D5;' ";
			}
			else{
				$CLSS = " class='contentlist' ";
			}
		}
		
			echo"
			<tr>
			 	<td width='10' $CLSS valign=top>
				<input type='hidden' name='versi' value='msword'>
				<input type='hidden' name='log_id' value='$log_id'>
				<input $CLSS type='checkbox' name='cv[]' value='$r[NIK]'></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>$r[NIK]</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>$r[Nama]</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>";
				
			// get latest carier
			//$sk = mssql_query("SELECT * FROM VKarirPtsi WHERE NIK='".$r[NIK]."' ORDER BY seqno DESC",$conn);
			//$rk = mssql_fetch_array($sk);
			//echo $rk[uraian];
			// get divisi
			$gdw = mssql_query("SELECT * FROM VLatestKarir WHERE NIK='$r[NIK]'",$conn);
			$rdw = mssql_fetch_array($gdw);
			//echo"$rdw[uraian]";
			
			if(empty($rdw[kode_so1])){
				$kodeso = $rdw[kode_so2];
			}
			else{
				$kodeso = $rdw[kode_so1];
			}
			
			$level1	= substr($kodeso,0,2); // direktorat
			$level2 = substr($kodeso,2,2); // koordinator
			$level3 = substr($kodeso,4,3); // cabang biro 
			$level4 = substr($kodeso,7,3); // bagian
			$level5 = substr($kodeso,10,2); //seksi
			
			$sql4 = mssql_query("select * from vlevelcabang where substring(kode_so,1,7)='".$level1.$level2.$level3."' order by kode_so",$conn);
			if(mssql_num_rows($sql4) > 0){
			$row4 = mssql_fetch_array($sql4);
				echo $row4[uraian];
			}
			
			echo"</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>";
			// get cabang
			//echo $rk[AreaCode];
			echo"</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>";
//			if(empty($pendidikan)){
				// get pendidikan
				if(!empty($pendidikan)){
					$pend = "AND Pend_ID='$pendidikan'";
				}
				
				$sp = mssql_query("SELECT keterangan,jurusan FROM CVPendidikan WHERE NIK='$r[NIK]' $pend",$conn);
				while($rp = mssql_fetch_array($sp)){
					echo"
					 <div>
					  &bull; $rp[keterangan] - $rp[jurusan]</li>
					 </div>
					";
				}
//			}
			echo"</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>";
				//get fungsional
				if(empty($r[fungsi1])){
					$fungsi = $r[fungsi2];
				}
				else{
					$fungsi = $r[fungsi1];
				}
				
				if(!empty($fungsi)){
					$sf = mssql_query("SELECT nama_fungsi FROM VFungsional WHERE kode_fungsi='$fungsi'",$conn);
					if(mssql_num_rows($sf) > 0){
						$rf = mssql_fetch_array($sf);
						echo"$rf[nama_fungsi]";
					}
				}
				else{
				}
								
				// get statu bekerja atau berhenti
				if($r[Jenis] == "U" || $r[Jenis] == "H"){
					$statusK = "Berhenti";
				}
				else{
					$statusK = "Bekerja";
				}
			echo"</a></td>
				<td $CLSS><a href='rep_cv.php?nik=$r[NIK]' target='_blank'>$statusK</a></td>
				<td $CLSS width=40 align=center>
				<a href='rep_cv.php?versi=msword&amp;nik=$r[NIK]&amp;log_id=$log_id' target='_blank' style='color: blue;'><img src='../images/down.png' border=0 alt='Download' title='Download CV'></a>";
			// cek dulu ke table dokumen pegawai
			$resB	= mssql_query("SELECT * FROM S_File_Emp WHERE NIK='".$r[NIK]."'",$conn);
			$SqlBCnt = mssql_num_rows($resB);
			if($SqlBCnt > 0){
				//$rowd = mssql_fetch_array($resB);
				echo"<a href=\"#\" OnClick=\"show_popup('../form/frm_emp_dokumen.php?nik=".$r[NIK]."')\"><img src='../images/down2.png' border=0 alt='Download Dokumen' title='Download Dokumen'></a>";
			}
			else{
				//echo"<a href='><img src='../images/down2.png' border=0 alt='Download Dokumen' title='Download Dokumen'></a>";
			}
			echo"</td>";
		echo"		
			</tr>
		";
			if(!empty($skill)){
				echo"
				 <tr>
				  <td colspan=7 class='contentlist'>&nbsp;</td>
				  <td colspan=5 bgcolor='#FFFFEA'><b>TRAINING/SKILL : </b>";
				// get skill kursus
				$gskill = mssql_query("SELECT * FROM CVKursus WHERE NIK='$r[NIK]' AND Program LIKE '%".$skill."%'",$conn);
				while($rskill = mssql_fetch_array($gskill)){
					echo"$rskill[Program], ";
				}
				echo"</td>
				 </tr>
				";
			}
			// pengalaman
			if(!empty($pengalaman)){
				echo"
				 <tr>
				  <td colspan=7 class='contentlist'>&nbsp;</td>
				  <td colspan=5 bgcolor='#FFFFEA'><b>PENGALAMAN : </b><br>";
				// get skill kursus
				$gtrack = mssql_query("SELECT year(Track_End) tahun, * FROM VTrackRecord WHERE NIK='$r[NIK]' AND (Project LIKE '%".$pengalaman."%')",$conn);
				while($rtrack = mssql_fetch_array($gtrack)){
					echo"&bull; $rtrack[tahun] $rtrack[Project], <br>";
				}
				echo"</td>
				 </tr>
				";
			}
			
		}
		echo"</table>
		<div class='table_indent2'>
		<form method='post' name='f1' action=''>
		[ <a href='Javascript:cek_all();'>Checklist Semua</a> | <a href='Javascript:not_cek_all();'>Unchecklist Semua</a> | <b>Download Checklist</b> ]
		</form>
		</div>
		";
	}
	else
	{
		echo"
		<table width=100%>
		<tr><td class=zerolist ><br><br>Maaf, pencarian tidak ditemukan ...</td></tr>
		</table>
		</form>
		<br>";
	}
}

elseif($show == "employee"){
	echo"
	<table>
	<tr height=10>
	 <td></td>
	</tr>
	</table>
	";
	SearchMK($cat,$conn,$st,$divisi,$sb);
	
	// pesan delete berhasil
	if($_GET['delete'] == "yes" && !empty($_GET['nik'])){
		$s1 = "delete from Karyawan where NIK='".$_GET['nik']."'";
		$s2 = "delete from Bahasa where NIK='".$_GET['nik']."'";
		$s3 = "delete from Cuti where NIK='".$_GET['nik']."'";
		$s4 = "delete from CutiTahunan where NIK='".$_GET['nik']."'";
		$s5 = "delete from Karir where NIK='".$_GET['nik']."'";
		$s6 = "delete from KaryawanFoto where NIK='".$_GET['nik']."'";
		$s7 = "delete from KaryawanStatus where NIK='".$_GET['nik']."'";
		$s8 = "delete from Keluarga where NIK='".$_GET['nik']."'";
		$s9 = "delete from Kenalan where NIK='".$_GET['nik']."'";
		$s10 = "delete from Kursus where NIK='".$_GET['nik']."'";
		$s11 = "delete from LP2 where NIK='".$_GET['nik']."'";
		$s12 = "delete from LP2Detail where NIK='".$_GET['nik']."'";
		$s13 = "delete from MedicalRestitusi where NIK='".$_GET['nik']."'";
		$s14 = "delete from MedicalRestitusiDetail where NIK='".$_GET['nik']."'";
		$s15 = "delete from MedicalSetupAwal where NIK='".$_GET['nik']."'";
		$s16 = "delete from MonitoringKontrak where NIK='".$_GET['nik']."'";
		$s17 = "delete from MK_TrackRecords where NIK='".$_GET['nik']."'";
		$s18 = "delete from MK_Certification where NIK='".$_GET['nik']."'";
		$s19 = "delete from Organisasi where NIK='".$_GET['nik']."'";
		$s20 = "delete from Pendidikan where NIK='".$_GET['nik']."'";
		$s21 = "delete from PengalamanLN where NIK='".$_GET['nik']."'";
		$s22 = "delete from PengalamanRef where NIK='".$_GET['nik']."'";
		$s23 = "delete from Penugasan where NIK='".$_GET['nik']."'";
		$s24 = "delete from Pribadi where NIK='".$_GET['nik']."'";
		$s25 = "delete from Sanksi where NIK='".$_GET['nik']."'";
		$s26 = "delete from Pendidikan where NIK='".$_GET['nik']."'";
		$s27 = "delete from TrainingKaryawan where NIK='".$_GET['nik']."'";
		
		$res_delete	= mssql_query($s1,$conn);
		$res_delete	= mssql_query($s2,$conn);
		$res_delete	= mssql_query($s3,$conn);
		$res_delete	= mssql_query($s4,$conn);
		$res_delete	= mssql_query($s5,$conn);
		$res_delete	= mssql_query($s6,$conn);
		$res_delete	= mssql_query($s7,$conn);
		$res_delete	= mssql_query($s8,$conn);
		$res_delete	= mssql_query($s9,$conn);
		$res_delete	= mssql_query($s10,$conn);
		$res_delete	= mssql_query($s11,$conn);
		$res_delete	= mssql_query($s12,$conn);
		$res_delete	= mssql_query($s13,$conn);
		$res_delete	= mssql_query($s14,$conn);
		$res_delete	= mssql_query($s15,$conn);
		$res_delete	= mssql_query($s16,$conn);
		$res_delete	= mssql_query($s17,$conn);
		$res_delete	= mssql_query($s18,$conn);
		$res_delete	= mssql_query($s19,$conn);
		$res_delete	= mssql_query($s20,$conn);
		$res_delete	= mssql_query($s21,$conn);
		$res_delete	= mssql_query($s22,$conn);
		$res_delete	= mssql_query($s23,$conn);
		$res_delete	= mssql_query($s24,$conn);
		$res_delete	= mssql_query($s25,$conn);
		$res_delete	= mssql_query($s26,$conn);
		$res_delete	= mssql_query($s27,$conn);
		
		?>
        <div align="center" style="padding:3px 3px 3px 3px; color:#0000FF;">Data Pegawai Sudah Dihapus</div>
        <?
	}
	
	echo"<table class='table_indent2' width='93%'>";
		if($HTTP_GET_VARS['st'] == "Pelamar"){
			// jika pelamar yang dipilih
			$sqlcount = "SELECT * FROM Karyawan WHERE (Nama LIKE '%$keyword%' OR NIK LIKE '%$keyword%' OR Alamat LIKE '%$keyword%') AND pelamar='1'";
		}
		else{
			$sqlcount = "SELECT * FROM VLatestKarir A, MstSO B WHERE A.kode_so2=B.kode_so AND B.AreaCode IN (";
			for($k=0;$k<count($VAreaCode);$k++){
				$sqlcount .= "'$VAreaCode[$k]',";
			}
			$sqlcount .= "'$VAreaCode[0]') ";
			$sqlcount .= " AND (Nama LIKE '%$keyword%' OR NIK LIKE '%$keyword%' OR Alamat LIKE '%$keyword%')";
			
			/*
			if(!empty($HTTP_GET_VARS['st'])){
				if($HTTP_GET_VARS['st'] == "Berhenti"){
					$sqlcount .= " AND Jenis IN ('U','H') ";			
				}
				else{
					if($HTTP_GET_VARS['st'] == "all"){
						// no command
					}
					else{
						$sqlcount .= " AND Jenis NOT IN ('U','H') AND (stat_kar1 = '".$HTTP_GET_VARS['st']."' OR stat_kar2='".$HTTP_GET_VARS['st']."') ";
					}
				}
			}
			*/
			
			if($HTTP_GET_VARS['st'] != "all"){
				$sqlcount .= " AND (stat_kar1 = '".$HTTP_GET_VARS['st']."' OR stat_kar2='".$HTTP_GET_VARS['st']."') ";
			}

			if($HTTP_GET_VARS['sb'] == "Berhenti"){
				$sqlcount .= " AND Jenis IN ('U','H') ";
			}

			if($HTTP_GET_VARS['sb'] == "Bekerja"){
				$sqlcount .= " AND Jenis NOT IN ('U','H') ";
			}
									
			if($HTTP_GET_VARS['jenkel'] == "0"){
				$sqlcount .= " AND JKel = '0'";
			}else{
				$sqlcount .= " AND JKel = '1'";
			}
									
			if(!empty($HTTP_GET_VARS['divisi'])){
				if($HTTP_GET_VARS['divisi'] == "all"){
				}
				else{
					$sqlcount .= " AND ( substring(kode_so1,1,7)='".substr($HTTP_GET_VARS['divisi'],0,7)."' OR substring(kode_so2,1,7)='".substr($HTTP_GET_VARS['divisi'],0,7)."' )";
				}
			}
		}
	//}
		
	$result	= mssql_query($sqlcount,$conn);
	$total	= mssql_num_rows($result);
	$limit	= 20;
	$pager  = Pager::getPagerData($total, $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;
	
	if($total > 0)
	{
		if($HTTP_GET_VARS['st'] == "Pelamar"){
			// jika pelamar yang dipilih
			$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM Karyawan WHERE (Nama LIKE '%$keyword%' OR NIK LIKE '%$keyword%' OR Alamat LIKE '%$keyword%') AND pelamar='1') SELECT * FROM limit WHERE No BETWEEN ".$offset." AND ".($offset+$limit)."";
		}
		else{
			$sql  = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM VLatestKarir A, MstSO B WHERE A.kode_so2=B.kode_so AND B.AreaCode IN (";
			
			for($k=0;$k<count($VAreaCode);$k++){
				$sql .= "'$VAreaCode[$k]',";
			}
			$sql .= "'$VAreaCode[0]') ";

			$sql .= " AND (Nama LIKE '%$keyword%' OR NIK LIKE '%$keyword%' OR Alamat LIKE '%$keyword%')";
			
			/*
			if(!empty($HTTP_GET_VARS['st'])){
				if($HTTP_GET_VARS['st'] == "Berhenti"){
					$sql .= " AND Jenis IN ('U','H') ";			
				}
				else{
					if($HTTP_GET_VARS['st'] == "all"){
						// no command
					}
					else{
						$sql .= " AND Jenis NOT IN ('U','H') AND (stat_kar1 = '".$HTTP_GET_VARS['st']."' OR stat_kar2='".$HTTP_GET_VARS['st']."') ";
					}
				}
			}
			*/
			
			if($HTTP_GET_VARS['st'] != "all"){
				$sql .= " AND (stat_kar1 = '".$HTTP_GET_VARS['st']."' OR stat_kar2='".$HTTP_GET_VARS['st']."') ";
			}

			if($HTTP_GET_VARS['sb'] == "Berhenti"){
				$sql .= " AND Jenis IN ('U','H') ";
			}

			if($HTTP_GET_VARS['sb'] == "Bekerja"){
				$sql .= " AND Jenis NOT IN ('U','H') ";
			}

			if($HTTP_GET_VARS['jenkel'] == "0"){
				$sql .= " AND JKel = '0'";
			}else{
				$sql .= " AND JKel = '1'";
			}
			
			if(!empty($HTTP_GET_VARS['divisi'])){
				if($HTTP_GET_VARS['divisi'] == "all"){
				}
				else{
					$sql .= " AND ( substring(kode_so1,1,7)='".substr($HTTP_GET_VARS['divisi'],0,7)."' OR substring(kode_so2,1,7)='".substr($HTTP_GET_VARS['divisi'],0,7)."' )";
				}
			}
			
			$sql .= " ) SELECT * FROM limit WHERE No BETWEEN ".$offset." AND ".($offset+$limit)."";
		}
		//echo $sql;
		Paging($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi,$sb);
		//echo"$sql <br><br>";
		echo"<table width=93% class='table_indent2'>";
		HeadKaryawanFront();
	$sqlxx = mssql_query($sql,$conn);
	while($row = mssql_fetch_array($sqlxx)){
		echo"
		<tr class='contentlist'>
		 <td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$row[No]</a></td>
		 <td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$row[NIK]</a></td>
		 <td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$row[Nama]</a></td>
		 <td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$row[Alamat]</a></td>
		 ";
		 
		$sqlx	= mssql_query("SELECT * FROM KarirPTSI WHERE NIK='$row[NIK]' ORDER BY seqno DESC",$conn);
		$rowx 	= mssql_fetch_array($sqlx);
				
		if(empty($rowx[kode_so1])){
			$kodeso = $rowx[kode_so2];
		}
		else{
			$kodeso = $rowx[kode_so1];
		}
		
		if(empty($kodeso)){
			echo"<td>&nbsp;</td>";
			echo"<td>&nbsp;</td>";
		}
		else{
			$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
			if(mssql_num_rows($s1) > 0){
				$r1 = mssql_fetch_array($s1);
				if(!empty($r1[uraian])){
					echo"<td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$r1[uraian]</a></td>";
				}
				else{
					echo"<td>&nbsp;</td>";
					echo"<td>&nbsp;</td>";
					echo"<td>&nbsp;</td>";
				}			
				$s3 = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='".$r1[kode_lokasi]."'",$conn);
				$r3 = mssql_fetch_array($s3);
				if(!empty($r3[distrik])){
					echo"<td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$r3[distrik]</a></td>";
				}
				else{
					echo"<td>&nbsp;</td>";
				}
			}
			else{
					echo"<td>&nbsp;</td>";
					echo"<td>&nbsp;</td>";
			}
		}	
		
		// get status karyawan
		if(empty($rowx[stat_kar1])){
			$status = $rowx[stat_kar2];
		}
		else{
			$status = $rowx[stat_kar1];
		}
			// jika yang dipilih berhenti
			if($rowx[Jenis] == "U" || $rowx[Jenis] == "H"){
				echo"<td>Berhenti</td>";
			}
			else{
				$s4 = mssql_query("SELECT * FROM VStatusKaryawan WHERE kode='".$status."'",$conn);
				$r4 = mssql_fetch_array($s4);
				if(!empty($r4[Nama])){
					echo"<td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>$r4[Nama]</a></td>";
				}
				else{
					if($row[pelamar] == "1"){
						echo"<td><a href='detailemp.php?show=data_umum&amp;nik=$row[NIK]'>Pelamar</a></td>";
					}
					else{
						echo"<td>&nbsp;</td>";
					}
				}
			}
		echo"
		 <td width=1%><a href='#' onclick='Javascript:del_emp(\"".$row[NIK]."\");'><img src='../images/b_delete.png' border='0' alt='Hapus Pegawai' title='Hapus Pegawai'></a></td>
		</tr>
		";
	}
	//ShowData($conn,$sql,$cat);
		echo"</table>";
	}
	else
	{
		echo"
		<table width=93% class='table_indent2'>
		<tr><td class=zerolist ><br><br>Maaf, pencarian tidak ditemukan ... <br><br>
		<a href='Javascript:history.back();'>Silahkan Kembali</a>
		</td></tr>
		</table><br>";
	}	
}

// untuk karir di ptsi
elseif($show == "karirptsi"){
// untuk hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='karir_ptsi'",$conn);
	$rpar = mssql_fetch_array($spar);	

	echo"
		<table width=100%>
		 <tr>
		  <td colspan=2 align=left>
		  <form method='get' action=search.php>
		  <fieldset><legend>Pencarian Karir Pegawai Selama di PT Surveyor Indonesia</legend>
		   <table border=0>
		    <tr>
			 <td width=145 align=left valign=top>&nbsp;&nbsp;Masukkan NIK/Nama:</td>
			 <td>
			 <input type='hidden' name='show' value='karirptsi'>
			 <input type='text' name='keyword'>";
	echo"
		<select name='divisi'>
		 <option value='all'>---semua divisi---</option>";
		$sq2 = mssql_query("SELECT * FROM VLevelCabang WHERE status='1' ORDER BY uraian ASC",$conn);
			while($rq2 = mssql_fetch_array($sq2)){
				echo"<option value='".$rq2[kode_so]."'";
				if($divisi == $rq2[kode_so]){
					echo" selected";
				}
			echo">$rq2[uraian]</option>";
		}
	echo"	 
		</select>
		</td>
		</tr>
		<tr>
		 <td>&nbsp;&nbsp;Status Karyawan:</td>
		 <td><select name='stat_kar'>
	    <option value='all'>--semua--</option>";
	$sq = mssql_query("SELECT * FROM VStatusKaryawan",$conn);
	while($rq = mssql_fetch_array($sq)){
		echo"<option value='".$rq[kode]."'";
		if($stat_kar == $rq[kode]){
			echo" selected";
		}
		echo">$rq[Nama]</option>";
	}
	echo"
        </select> &nbsp;&nbsp;Status Karyawan <select name=\"st\">
   <option value=\"all\">--semua--</option>
   <option value=\"bekerja\""; 
   if($st=="bekerja"){ echo" selected"; } echo">Bekerja</option>";
   echo"<option value=\"berhenti\""; 
   if($st=="berhenti"){ echo" selected"; } echo">Berhenti</option>
   </select></td>
		</tr>
		<tr>
		 <td></td>
		 <td>
	";
	echo"		 
			 <input type=submit value='Cari' class=button>";
		// untuk hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='karir_ptsi'",$conn);
	$rpar = mssql_fetch_array($spar);			  
		// tambah
		if($rpar[tambah] == 1){
		echo"<input type=button value='Tambah' class='button' onclick='Javascript:location.href=\"../form/frm_karir_ptsi.php\"'></td>";
		}
			 echo"</td>
			</tr>
		   </table>
		  </td>
		 </tr>
		";

		$sql_num 	 = "SELECT NIK,Nama FROM  VLatestKarir A, MstSO B WHERE A.kode_so2=B.kode_so AND B.AreaCode IN (";
		for($k=0;$k<count($VAreaCode);$k++){
			$sql_num .= "'$VAreaCode[$k]',";
		}
		$sql_num 	.= "'$VAreaCode[0]') ";
		$sql_num	.= " AND (NIK LIKE '%$keyword%' OR Nama LIKE '%$keyword%') ";
		
			if($divisi == "all"){
			// no command
			}
			else{
				$sql_num .= " AND substring(kode_so2,1,7) = '".substr($divisi,0,7)."' ";
			}
			
			if($stat_kar == "all"){
			// no command
			}
			else{
				$sql_num .= " AND stat_kar2='$stat_kar'";
			}
			
			if($st == "all"){
			// no command
			}
			else{
				if($st == "bekerja"){
					$sql_num .= " AND Jenis NOT IN ('U','H') ";
				}
				elseif($st == "berhenti"){
					$sql_num .= " AND Jenis IN ('U','H') ";
				}
			}
			
		$sql_num		.= " GROUP BY NIK,Nama";
		//$cnt_num	= mssql_num_rows($sql_num);	
		
		$result	= mssql_query($sql_num,$conn);
		$total	= mssql_num_rows($result);
		$limit	= 15;
		$pager  = Pager::getPagerData($total, $limit, $page);
		$offset = $pager->offset;
		$limit  = $pager->limit;
		$page   = $pager->page;	
		
		if($total > 0){

		$sqlx = "WITH AAA AS(SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, NIK, Nama, kode_so2, stat_kar2, jenis FROM VLatestKarir A, MstSO B WHERE A.kode_so2=B.kode_so AND B.AreaCode IN ( ";

		for($k=0;$k<count($VAreaCode);$k++){
			$sqlx .= "'$VAreaCode[$k]',";
		}
		$sqlx 	.= "'$VAreaCode[0]') ";

		$sqlx .= " AND (NIK LIKE '%$keyword%' OR Nama LIKE '%$keyword%') ";
		if($divisi == "all"){
		// no command
		}
		else{
			$sqlx .= " AND substring(kode_so2,1,7) = '".substr($divisi,0,7)."' ";
		}
		
		if($stat_kar == "all"){
		// no command
		}
		else{
			$sqlx .= " AND stat_kar2='$stat_kar'";
		}
		
		if($st == "all"){
		// no command
		}
		else{
			if($st == "bekerja"){
				$sqlx .= " AND Jenis NOT IN ('U','H') ";
			}
			elseif($st == "berhenti"){
				$sqlx .= " AND Jenis IN ('U','H') ";
			}
		}
		
		$sqlx .= " GROUP BY NIK,Nama, kode_so2, stat_kar2, jenis ) SELECT * FROM AAA WHERE No BETWEEN $offset AND ".($limit+$offset)."";
		
		$sql = mssql_query($sqlx,$conn);
		
		 echo"
		 <tr>
		  <td colspan=2>";
		//Paging($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi);
		PagingLapTr($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi,$stat_kar,$pendidikan,$jabatan,$golongan,$bulan1,$bulan2,$tahun2,$tahun1,$jns_kursus);

		 echo"</td>
		 </tr>
		 <tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			 <td>Divisi/Biro/Unit Kerja</td>
			 <td>Status Karyawan</td>
			 <td>Status Kerja</td>
			</tr>";

			while($row = mssql_fetch_array($sql)){
			  echo"<tr class=contentlist>
				 <td class=contentlist><a href='list_karir.php?show=list_karir&amp;nik=$row[NIK]'>$row[No]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_karir&amp;nik=$row[NIK]'>$row[NIK]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_karir&amp;nik=$row[NIK]'>$row[Nama]</a></td>";
				 echo"<td>";			 
				 if(!empty($row[kode_so2])){
				 	// get status karyawan
					$sst = mssql_query("SELECT uraian FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($row[kode_so2],0,7)."'",$conn);
					$rst = mssql_fetch_array($sst);
					echo"$rst[uraian]";
				 }
				 else{
				 	echo"&nbsp;";
				 }
				 echo"</td><td>";
				 if(!empty($row[stat_kar2])){
				 	// get status karyawan
					$sstx = mssql_query("SELECT nama FROM VStatusKaryawan WHERE kode='".$row[stat_kar2]."'",$conn);
					$rstx = mssql_fetch_array($sstx);
					echo"$rstx[nama]";
				 }
				 else{
				 	echo"&nbsp;";
				 }
				 echo"</td>";
				 // get status kerja
				 $sqlvvv = mssql_query("SELECT Jenis FROM VLatestKarir WHERE NIK = '$row[NIK]'",$conn);
				 if(mssql_num_rows($sqlvvv) > 0){
					 $rowvvv = mssql_fetch_array($sqlvvv);
					 if($rowvvv[Jenis] == "U" || $rowvvv[Jenis] == "H"){
					 	echo"<td>Berhenti</td>";	
					 }
					 else{
					 	echo"<td>Bekerja</td>";
					 }
				 }
				 else{
				 	echo"<td>&nbsp;</td>";
				 }
				 
				 echo"</tr>";
			}
			//echo"Ada";
		}
		else{
			echo"
			<tr>
			 <td align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			//exit();
		}
	   echo"</table>
		  </td>
		 </tr>
		</table>
	";
}
// untuk karir di track record
elseif($show == "track_record"){
	// hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='track_record'",$conn);
	$rpar = mssql_fetch_array($spar);	

	echo"
		<table width=93% class='table_indent2'>
		 <tr>
		  <td colspan=2 class=line_bottom>&nbsp;&nbsp;<b>PENCARIAN TRACK RECORD</b></td>
		 </tr>
		 <tr>
		  <td colspan=2 align=center>
		  <form method='get' action=search.php>
		   <table>
		    <tr>
			 <td width=200 align=right>Masukkan NIK/Nama:</td>
			 <td>
			 <input type='hidden' name='show' value='track_record'>
			 <input type='text' name='keyword'><input type=submit value='Cari' class=button></td>
			</tr>
		   </table>
		  </form>
		  </td>
		 </tr>
		 <tr>
		  <td><hr noshade size=-2></td>
		 </tr>
		 <tr>
		  <td colspan=2>";
		// tambah
		if($rpar[tambah] == 1){
		echo'
		  <input type=button class=button value=Tambah onclick=Javascript:location.href="../form/frm_emp_track_record.php" />';
		}
		echo'</td>
		 </tr>';
/*
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlxxy .= "'$VAreaCode[$k]',";
		}
		$sqlxxy	.= "'$VAreaCode[0]')";

*/	 
		$sqlx	= "SELECT A.NIK FROM VTrackRecord A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlx .= "'$VAreaCode[$k]',";
		}
		$sqlx	.= "'$VAreaCode[0]')";
		
		$sqlx	.= " GROUP BY A.NIK";
		$sql_num 	= mssql_query($sqlx,$conn);

		$total	= mssql_num_rows($sql_num);
		$limit	= 15;
		$pager  = Pager::getPagerData($total, $limit, $page);
		$offset = $pager->offset;
		$limit  = $pager->limit;
		$page   = $pager->page;	

		if($total > 0){
		 echo"
		 <tr>
		  <td colspan=2>";
		  Paging($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi,$sb);
		  /*
		$sqlx	= "SELECT A.NIK FROM VTrackRecord A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlx .= "'$VAreaCode[$k]',";
		}
		$sqlx	.= "'$VAreaCode[0]')";
		
		$sqlx	.= " GROUP BY A.NIK";
		  
		  */
		  $sqly	= "WITH Q AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama FROM VTrackRecord A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqly .= "'$VAreaCode[$k]',";
		}
		$sqly	.= "'$VAreaCode[0]')";
		
		$sqly .= " GROUP BY A.NIK,A.Nama) SELECT * FROM Q WHERE No BETWEEN $offset AND ".($offset+$limit)."";
		  
		  $sql = mssql_query($sqly,$conn);
		 echo"</td>
		 </tr>
		 <tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			</tr>";
			while($row = mssql_fetch_array($sql)){
			  echo"<tr>
				 <td class=contentlist><a href='list_karir.php?show=list_track_record&amp;nik=$row[NIK]'>$row[No]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_track_record&amp;nik=$row[NIK]'>$row[NIK]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_track_record&amp;nik=$row[NIK]'>$row[Nama]</a></td>
				</tr>";
			}
			//echo"Ada";
		}
		else{
			echo"
			<tr>
			 <td align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			exit();
		}
	   echo'</table>
		  </td>
		 </tr>
		</table>
	';
}
// untuk PENCARIAN SANKSI
elseif($show == "sanksi"){
// hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='sanksi'",$conn);
	$rpar = mssql_fetch_array($spar);	

	echo"
		<table width=93% class='table_indent2'>
		 <tr>
		  <td colspan=2>
		  ";
		  SearchSanksi($conn,$st,$filter,$show,$keyword,$b1,$b2,$t1,$t2);
		  echo"</td>
		 </tr>
		 <tr>
		  <td><hr noshade size=-2></td>
		 </tr>
		 <tr>
		  <td colspan=2>";
	   // tambah
	   if($rpar[tambah] == 1){
	   echo'
		  <input type=button class=button value=Tambah onclick=Javascript:location.href="../form/frm_emp_sanksi.php" />';
	   }
	   echo'</td>
		 </tr>';
		 
		$sqlsearch = "WITH Q AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama ";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlsearch .=" ,category ";
		}
		
		//$sqlsearch .=" FROM VSanksi ";
		$sqlsearch .=" FROM VSanksi A, VLatestKarir B, MstSO C WHERE B.kode_so2=C.kode_so AND A.NIK=B.NIK AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlsearch .= "'$VAreaCode[$k]',";
		}
		
		$sqlsearch 	.= "'$VAreaCode[0]')";	
		
		if(!empty($HTTP_GET_VARS['keyword'])){
			$sqlsearch .=" AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%')";
		}
		
		if(!empty($HTTP_GET_VARS['st'])){
			if($HTTP_GET_VARS['st'] == "bekerja"){
				$sqlsearch .=" AND Jenis NOT IN ('U','H')";
			}
			elseif($HTTP_GET_VARS['st'] == "berhenti"){
				$sqlsearch .=" AND Jenis IN ('U','H')";
			}
		}
			
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlsearch .=" AND A.category='".$HTTP_GET_VARS['filter']."'";
		}
									
		if(!empty($HTTP_GET_VARS['b1']) && !empty($HTTP_GET_VARS['b2'])){
			if(empty($HTTP_GET_VARS['keyword']) && empty($HTTP_GET_VARS['filter'])){
				$sqlsearch .= " AND (month(tgl_laku) BETWEEN '".$HTTP_GET_VARS['b1']."' AND '".$HTTP_GET_VARS['b2']."') ";
			}
			else{
				$sqlsearch .= " AND (month(tgl_laku) BETWEEN '".$HTTP_GET_VARS['b1']."' AND '".$HTTP_GET_VARS['b2']."') ";
			}
		} 
			
		if(!empty($HTTP_GET_VARS['t1']) && !empty($HTTP_GET_VARS['t2'])){
			$sqlsearch .= " AND (year(tgl_laku) BETWEEN '".$HTTP_GET_VARS['t1']."' AND '".$HTTP_GET_VARS['t2']."')";
		}
		//*/
										
		$sqlsearch .=" GROUP BY A.NIK,A.Nama";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlsearch .=" ,category ";
		}

		$sqlsearch .=") SELECT Nama,NIK ";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlsearch .=" ,category ";
		}

		$sqlsearch .=" FROM Q GROUP BY Nama,NIK";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlsearch .=" ,category ";
		}

	  //echo $sqlsearch;

		//$sql 		= mssql_query($sqlsearch,$conn);			
		$sql_num 	= mssql_query($sqlsearch,$conn);
		$cnt_num	= mssql_num_rows($sql_num);	

		//$result	= mssql_query($sql_num,$conn);
		$total	= mssql_num_rows($sql_num);
		$limit	= 15;
		$pager  = Pager::getPagerData($total, $limit, $page);
		$offset = $pager->offset;
		$limit  = $pager->limit;
		$page   = $pager->page;	

		if($cnt_num > 0){
		
		 echo"
		 <tr>
		  <td colspan=2>";
		  		Paging($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi);

		$sqlvvv = "WITH Q AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama, Jenis ";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlvvv .=" ,category ";
		}
		else{
			// no command
		}
		
		$sqlvvv .=" FROM VSanksi A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlvvv .= "'$VAreaCode[$k]',";
		}
		
		$sqlvvv 	.= "'$VAreaCode[0]')";	
				
		if(!empty($HTTP_GET_VARS['st'])){
			if($HTTP_GET_VARS['st'] == "bekerja"){
				$sqlvvv .=" AND Jenis NOT IN ('U','H')";
			}
			elseif($HTTP_GET_VARS['st'] == "berhenti"){
				$sqlvvv .=" AND Jenis IN ('U','H')";
			}
		}
			
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlvvv .=" AND category='".$HTTP_GET_VARS['filter']."'";
		}
		else{
			// no command
		}
									
		if(!empty($HTTP_GET_VARS['b1']) && !empty($HTTP_GET_VARS['b2'])){
			if(empty($HTTP_GET_VARS['keyword']) && empty($HTTP_GET_VARS['filter'])){
				//$sqlvvv .= " AND (month(tgl_laku) BETWEEN '".$HTTP_GET_VARS['b1']."' AND '".$HTTP_GET_VARS['b2']."') ";
			}
			else{
				$sqlvvv .= " AND (month(tgl_laku) BETWEEN '".$HTTP_GET_VARS['b1']."' AND '".$HTTP_GET_VARS['b2']."') ";
			}
		} 
					
		if(!empty($HTTP_GET_VARS['t1']) && !empty($HTTP_GET_VARS['t2'])){
			$sqlvvv .= " AND (year(tgl_laku) BETWEEN '".$HTTP_GET_VARS['t1']."' AND '".$HTTP_GET_VARS['t2']."')";
		}
		//*/
										
		$sqlvvv .=" GROUP BY A.NIK,A.Nama,B.Jenis";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlvvv .=" ,category ";
		}
		else{
		
		}

		$sqlvvv .=") SELECT Nama,NIK,Jenis ";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlvvv .=" ,category ";
		}

		$sqlvvv .=", No FROM Q WHERE No BETWEEN $offset AND ".($limit+$offset)." ";

		if(!empty($HTTP_GET_VARS['keyword'])){
			$sqlvvv .=" AND NIK LIKE '%$keyword%' OR Nama LIKE '%$keyword%'";
		}

		$sqlvvv .=" GROUP BY Nama,NIK,No,Jenis";
		
		if(!empty($HTTP_GET_VARS['filter'])){
			$sqlvvv .=" ,category ";
		}

		$sqlvvv	.= " ORDER BY No ASC ";
		$sqlvvvw = mssql_query($sqlvvv,$conn);
		 echo"</td>
		 </tr>
		 <tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			 <td>Kategori Sanksi</td>
			 <td>Status Kerja</td>
			</tr>";
			while($row = mssql_fetch_array($sqlvvvw)){
			  echo"<tr class=contentlist>
				 <td class=contentlist><a href='list_karir.php?show=list_sanksi&amp;nik=$row[NIK]'>$row[No]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_sanksi&amp;nik=$row[NIK]'>$row[NIK]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_sanksi&amp;nik=$row[NIK]'>$row[Nama]</a></td>";
			  $qsk = mssql_query("SELECT * FROM VKatSanksi WHERE kode='$row[category]'",$conn);
			  $rsk = mssql_fetch_array($qsk);
			  echo"<td>$rsk[nama]</td>";
			  if($row[Jenis] == "U" || $row[Jenis] == "H"){
			  		$sts = "Berhenti";
			  }
			  else{
			  		$sts = "Bekerja";
			  }
			  echo"<td>".strtoupper($sts)."</td>";
			  echo"</tr>";
			}
		}
		else{
			echo"
			<tr>
			 <td align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			exit();
		}
	   echo'</table>
		  </td>
		 </tr>
		</table>
	';
}
// untuk PENCARIAN PENUGASAN
elseif($show == "penugasan"){
	// hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='penugasan'",$conn);
	$rpar = mssql_fetch_array($spar);	

	echo"
		<table width=93% class='table_indent2'>
		 <tr>
		  <td colspan=2 class=line_bottom>&nbsp;&nbsp;<b>PENCARIAN PENUGASAN</b></td>
		 </tr>
		 <tr>
		  <td colspan=2 align=center>
		  <form method='get' action=search.php>
		   <table>
		    <tr>
			 <td width=200 align=right>Masukkan NIK/Nama:</td>
			 <td>
			 <input type='hidden' name='show' value='penugasan'>
			 <input type='text' name='keyword'><input type=submit value='Cari' class=button></td>
			</tr>
		   </table>
		  </form>
		  </td>
		 </tr>
		 <tr>
		  <td><hr noshade size=-2></td>
		 </tr>
		 <tr>
		  <td colspan=2>";
		// tambah
		if($rpar[tambah] == 1){
		echo'
		  <input type=button class=button value=Tambah onclick=Javascript:location.href="../form/frm_emp_penugasan.php" />';
		}
		echo'</td>
		 </tr>';
//		$sql_num 	= mssql_query("SELECT NIK FROM VPenugasan WHERE NIK LIKE '%$keyword%' OR Nama LIKE '%$keyword%' GROUP BY NIK",$conn);
		$sqlxx 	= "SELECT A.NIK FROM VPenugasan A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlxx .= "'$VAreaCode[$k]',";
		}
		$sqlxx 	.= "'$VAreaCode[0]')";
		
		$sqlxx	.= " GROUP BY A.NIK";
		
		$sql_num= mssql_query($sqlxx,$conn);
		$total	= mssql_num_rows($sql_num);
		$limit	= 15;
		$pager  = Pager::getPagerData($total, $limit, $page);
		$offset = $pager->offset;
		$limit  = $pager->limit;
		$page   = $pager->page;	
		
		if($total > 0){
		echo"
		<tr>
		 <td colspan=2>
		";
		Paging($pager,$page,$next,$limit,$keyword,$show,$conn,$st,$divisi,$sb);

		$sqlxxy = "WITH Q AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama FROM VPenugasan A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlxxy .= "'$VAreaCode[$k]',";
		}
		$sqlxxy	.= "'$VAreaCode[0]')";
		$sqlxxy .= " GROUP BY A.NIK,A.Nama) SELECT * FROM Q WHERE No BETWEEN $offset AND ".($offset+$limit)."";
		
		$sql = mssql_query($sqlxxy,$conn);

		 echo"</td></tr><tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			</tr>";

			while($row = mssql_fetch_array($sql)){
			  echo"<tr>
				 <td class=contentlist><a href='list_karir.php?show=list_tugas&amp;nik=$row[NIK]'>$row[No]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_tugas&amp;nik=$row[NIK]'>$row[NIK]</a></td>
				 <td class=contentlist><a href='list_karir.php?show=list_tugas&amp;nik=$row[NIK]'>$row[Nama]</a></td>
				</tr>";
			}
			//echo"Ada";
		}
		else{
			echo"
			<tr>
			 <td align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			exit();
		}
	   echo'</table>
		  </td>
		 </tr>
		</table>
	';
}
// untuk PENCARIAN PENILAIAN
elseif($show == "penilaian"){
	echo"
		<table width=93% class='table_indent2'>
		 <tr>
		  <td colspan=2 class=line_bottom>&nbsp;&nbsp;<b>PENCARIAN PENILAIAN</b></td>
		 </tr>
		 <tr>
		  <td colspan=2 align=center>
		  <form method='get' action=search.php>
		   <table>
		    <tr>
			 <td width=200 align=right>Masukkan NIK/Nama:</td>
			 <td>
			 <input type='hidden' name='show' value='penilaian'>
			 <input type='text' name='keyword'><input type=submit value='Cari' class=button></td>
			</tr>
		   </table>
		  </form>
		  </td>
		 </tr>
		 <tr>
		  <td><hr noshade size=-2></td>
		 </tr>
		 <tr>
		  <td colspan=2>&nbsp;</td>
		 </tr>";
		 $sqlxx = "SELECT A.* FROM VLP A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlxx .= "'$VAreaCode[$k]',";
		}
		
		$sqlxx 	.= "'$VAreaCode[0]')";	
		
		$sql_num 	= mssql_query($sqlxx,$conn);
		$cnt_num	= mssql_num_rows($sql_num);	
		
		if($cnt_num > 0){
		 echo"<tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			 <td>Divisi</td>
			 <td>Periode</td>
			 <td>Hasil</td>
			 <td>&nbsp;</td>
			 <td>&nbsp;</td>
			</tr>";
			$sqlxy  = "SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama, periode,id FROM VLP A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%' AND C.AreaCode IN (";
			
			for($k=0;$k<count($VAreaCode);$k++){
				$sqlxy .= "'$VAreaCode[$k]',";
			}
			
			$sqlxy 	.= "'$VAreaCode[0]')";	
			
			$sqlxy .= " GROUP BY A.NIK,A.Nama,periode,id";

			$sql = mssql_query($sqlxy,$conn);
			while($row = mssql_fetch_array($sql)){
			// get last karir
			$slk = mssql_query("SELECT NIK, kode_so2 FROM VLatestKarir WHERE NIK='$row[NIK]'",$conn);
			$rlk = mssql_fetch_array($slk);
			// get nama karir
			$scb = mssql_query("SELECT uraian FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($rlk[kode_so2],0,7)."'",$conn);
			$rcb = mssql_fetch_array($scb);	
			  echo"<tr class=contentlist>
				 <td class=contentlist>$row[No]</td>
				 <td class=contentlist><a href='../form/frm_emp_fpenilaian.php?id=$row[id]&amp;op=edit'>$row[NIK]</a></td>
				 <td class=contentlist><a href='../form/frm_emp_fpenilaian.php?id=$row[id]&amp;op=edit'>$row[Nama]</a></td>
				 <td class=contentlist><a href='../form/frm_emp_fpenilaian.php?id=$row[id]&amp;op=edit'>$rcb[uraian]</a></td>
				 <td class=contentlist><a href='../form/frm_emp_fpenilaian.php?id=$row[id]&amp;op=edit'>$row[periode]</a></td>
				 <td class=contentlist 'align=center'><a href='../report/rep_rekap_lpkp.php?nik=$row[NIK]&periode=$row[periode]' target='_blank'><img src='../images/fileprint.png' title='Preview' alt='Preview' border=0></a></td>
				 <td><i><a href='#' onclick='Javascript:window.open(\"detail_lp.php?nik=$row[NIK]&amp;periode=$row[periode]\",\"\",\"scrollbars=no,width=600,height=440,left=150,top=120\")'>detail</a></i></td>
				 <td>
					<a href='#' Onclick='Javascript:hapus2(\"LP\",\"$rowcuti[NIK]\",\"$row[id]\");'><img src='../images/b_delete.png' title='Delete' alt='Delete' border='0'>
				 </td>
				</tr>";
			}
			//echo"Ada";
		}
		else{
			echo"
			<tr>
			 <td align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b><br><br>
		  	<input type=button value=\"Tambah\" class=\"button\" onclick=Javascript:location.href=\"../form/frm_emp_fpenilaian.php\">
			 </td>
			</tr>
			";
			//exit();
		}
	   echo'</table>
		  </td>
		 </tr>
		 <tr>
		  <td colspan=2>
		  <br><br><br>
		  <input type=button value="Tambah" class="button" onclick=Javascript:location.href="../form/frm_emp_fpenilaian.php">
		 </tr>
		</table>
	';
}

// untuk PENCARIAN CUTI
elseif($show == "cuti"){
	$sparC = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='cuti'",$conn);
	$rparC = mssql_fetch_array($sparC);	
	echo"
		<table width=100% class='table_indent2'>
		 <tr>
		  <td colspan=2 class=line_bottom>&nbsp;&nbsp;<b>PENCARIAN CUTI KARYAWAN</b></td>
		 </tr>
		 <tr>
		  <td colspan=2 align=left>";
	SearchCuti($conn,$bulan1,$bulan2,$tahun1,$tahun2,$divisi);	  
	echo"</td>
		 </tr>
		 <tr>
		  <td colspan=2>";
				
///////////////////////////////////// BEGIN KHUSUS CUTI TAHUNAN ////////////////////////////////////////////		
if($HTTP_GET_VARS['jenis_cuti'] == "CT"){

		// untuk persetujuan cuti tahunan  
		if($HTTP_GET_VARS['appr'] == "yes" && $HTTP_GET_VARS['jenis_cuti'] == "CT" && $HTTP_GET_VARS['ambil'] == "0" && $HTTP_GET_VARS['tunda'] == "0"){
			$sql = mssql_query("WITH limit AS (SELECT * FROM CutiTahunan WHERE NIK='".$nik."' AND id='".$no."') UPDATE limit SET aktif='A', ambil='0', tunda='0' WHERE id='".$no."'",$conn);
		}
			
		if($HTTP_GET_VARS['appr'] == "yes" && $HTTP_GET_VARS['jenis_cuti'] == "CT" && $HTTP_GET_VARS['tunda'] == "1"){
			$sql = mssql_query("WITH limit AS (SELECT * FROM CutiTahunan WHERE NIK='".$nik."' AND id='".$no."') UPDATE limit SET aktif='A', ambil='0', tunda='1' WHERE id='".$no."'",$conn);
		}
				
		if($HTTP_GET_VARS['appr'] == "yes" && $HTTP_GET_VARS['jenis_cuti'] == "CT" && $HTTP_GET_VARS['ambil'] == 1  && $HTTP_GET_VARS['tunda'] == 1){
			$sql = mssql_query("WITH limit AS (SELECT * FROM CutiTahunan WHERE NIK='".$nik."' AND id='".$no."') UPDATE limit SET aktif='A', ambil='1' WHERE id='".$no."'",$conn);
		}
		
	  /////////////////////////////////////////////////////////////////////////////////////
	  // get JUMLAH pengajuan cuti tahunan ////////////////////////////////////////////////
	  /////////////////////////////////////////////////////////////////////////////////////
	  $qx		 = "SELECT count(*) FROM CutiTahunan A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND C.AreaCode IN (";
	  
	for($k=0;$k<count($VAreaCode);$k++){
		$qx .= "'$VAreaCode[$k]',";
	}
	
	$qx 	.= "'$VAreaCode[0]')";	

	  // cek keyword
	  if(!empty($keyword)){
	  		$qx .= " AND (A.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%') ";
	  }
	  else{
	  }

	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}

	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$qx .= " and tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
	 	 
		 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$qx .= " and tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
		 elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$qx .= " and tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}
	  // cek divisi
	 if(!empty($HTTP_GET_VARS['divisi'])){
		$qx .= " AND (substring(B.kode_so1,1,7)='".substr($divisi,0,7)."' OR (substring(B.kode_so2,1,7)='".substr($divisi,0,7)."'))";
	 }
	 
	 // cek status
	 if(!empty($HTTP_GET_VARS['status'])){
	 	if($HTTP_GET_VARS['status'] == "A"){
			$qx .= " AND (aktif='A')";
		}
		else{
			$qx .= "AND (aktif='P' OR aktif='T')";
		}
	 } 
	 else{
			$qx .= "AND (aktif='P' OR aktif='T')";
	 }
	  
	  $sqlcutix = mssql_query($qx,$conn);
		
	//$result	= mssql_query("SELECT count(*) FROM Karyawan",$conn);
	$total	= mssql_fetch_row($sqlcutix);
	$limit	= 15;
	$pager  = Pager::getPagerData($total[0], $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;
	
	PagingMedCut($pager,$page,$next,$limit,$keyword,$show,$conn,$status,$divisi,$bulan1,$bulan2,$tahun1,$tahun2,$jenis_cuti);
		
		echo"
		<fieldset>
		 <legend><b>Daftar Pengajuan CUTI TAHUNAN</b></legend>
		 <table width='100%'>
		  <tr class=headlist>
		   <td>No</td>
		   <td>Tanggal Cuti</td>
		   <td>NIK</td>
		   <td>Nama</td>
		   <td>Divisi/Biro/Unit Kerja</td>
		   <td>Periode</td>
		   <td>Sisa Cuti</td>
		   <td width=150>Status</td>
		   <td>&nbsp;</td>
		  </tr>";
	  // get pengajuan cuti tahunan

	  $sqlcutixy	= "WITH ABCD AS (SELECT ROW_NUMBER() OVER (ORDER BY A.tgl_cuti DESC) AS No, A.*, B.kode_so2, B.kode_so1 FROM VCutiTahunan A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND C.AreaCode IN (";
	    for($k=0;$k<count($VAreaCode);$k++){
			$sqlcutixy .= "'$VAreaCode[$k]',";
		}
		
		$sqlcutixy 	.= "'$VAreaCode[0]')";	

	  // cek divisi
	 if(!empty($HTTP_GET_VARS['divisi'])){
		$sqlcutixy .= " AND substring(kode_so2,1,7)='".substr($HTTP_GET_VARS['divisi'],0,7)."'";
	 }
	  // cek nama
	  if(!empty($keyword)){
	  $sqlcutixy 	.= "AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%')";
	  }
	
	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}
	
	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$sqlcutixy .= " and A.tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
	 	 
		 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$sqlcutixy .= " and A.tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
		 elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$sqlcutixy .= " and A.tgl_cuti between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}
	 
	 // cek status
	 if(!empty($HTTP_GET_VARS['status'])){
	 	if($HTTP_GET_VARS['status'] == "A"){
			$sqlcutixy .= " AND aktif='A'";
		}
		elseif($HTTP_GET_VARS['status'] == "P"){
			$sqlcutixy .= "AND (aktif='P' OR aktif='T')";
		}
	 } 
	 else{
			$sqlcutixy .= "AND (aktif='P' OR aktif='T')";
	 }
	  
	  $sqlcutixy	.= ") SELECT CONVERT(CHAR(12), tgl_cuti, 103) Tgl, * FROM ABCD WHERE No BETWEEN ".$offset." AND ".($offset+$limit)."";
	  
	  
	  $sqlcutixy .= " ORDER BY tgl_cuti DESC";
	  $sqlcuti = mssql_query($sqlcutixy,$conn);
		  while($rowcuti = mssql_fetch_array($sqlcuti)){
		  	echo"
			<tr class=contentlist>
			 <td align=right> $rowcuti[No]</td>
			 <td>$rowcuti[Tgl]</td>
			 <td>$rowcuti[NIK]</td>
			 <td>$rowcuti[Nama]</td>";
			 
			$kodeso = $rowcuti[kode_so2];
			
			if(empty($kodeso)){
			}
			else{
				$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
				if(mssql_num_rows($s1) > 0){
					$r1 = mssql_fetch_array($s1);
					if(!empty($r1[uraian])){
						echo"<td style='font-size:8px;'>$r1[uraian]</td>";
					}
					else{
						echo"<td>&nbsp;</td>";
					}			
				}
				else{
						echo"<td>&nbsp;</td>";
				}
			}	
		
			echo"
			 <td style='font-size:9px;'>$rowcuti[periode]</td>
			 <td align=center>";
			////////////////// get sisa cuti  
            // get jatah cuti tahunan
            $gj = mssql_query("SELECT jatah_cuti, syarat_waktu FROM VJCuti WHERE nama='Cuti Tahunan'",$conn);
            $rj = mssql_fetch_array($gj);
            $jatah_cuti = $rj[jatah_cuti];
            $syarat_cuti= $rj[syarat_waktu];
			// sisa cuti
			$sqlsisa 	= mssql_query("SELECT count(*) jumlah FROM CutiTahunan WHERE NIK='$rowcuti[NIK]' AND periode='$rowcuti[periode]' AND aktif IN ('A',NULL) AND (ambil='1' OR tunda='0')",$conn);
			$cntsisa 	= mssql_fetch_array($sqlsisa);
			$sisa_cuti	= $jatah_cuti - $cntsisa[jumlah];
			
			echo"$sisa_cuti</td>
			 <td>";
			 if($rowcuti[aktif] == "A"){
			 	echo"Disetujui";
			 }
			 elseif($rowcuti[aktif] == "T"){
			 	echo"<span style='color: red; font-size: 9px;'>(<b>Pengajuan Cuti Tunda $rowcuti[keterangan]</b>)</span>";
			 }
			 else{
			 	if($rowcuti[tunda] == 1){
				 	echo"<span style='color: red; font-size: 9px;'>(<b>Pengajuan Tunda Cuti</b>)</span>";
				}
				else{
				 	echo"<span style='color: red; font-size: 9px;'>(<b>Pengajuan Cuti</b>)</span>";
				}
			 }
			echo"</td>
			<td><a href='../report/rep_cuti.php?nik=$rowcuti[NIK]&amp;cuti=tahunan&amp;no=$rowcuti[id]&amp;periode=$rowcuti[periode]' target='_blank'><img src='../images/fileprint.png' title='Cetak Surat Permohonan' alt='Cetak Surat Permohonan' border=0></a>";
			// approval
			if($rparC[approval] == 1){
			echo"
			<a href='#' Onclick='Javascript:appr_per(\"cuti\",\"".$pert."\",\"$rowcuti[NIK]\",\"$rowcuti[id]\",\"$rowcuti[ambil]\",\"$rowcuti[tunda]\",\"CT\");'><img src='../images/apply.png' title='Approval/\Persetujuan' alt='Approval/\Persetujuan' border=0></a>";
			}
			// edit
			if($rparC[edit] == 1){
			echo"
			<a href='../form/frm_emp_cuti.php?show=cuti_tahunan_ed&amp;op=edit&amp;nik=$rowcuti[NIK]&amp;no=$rowcuti[id]'><img src='../images/b_edit.png' title='Edit' alt='Edit' border=0></a>";
			}
			//hapus
			if($rparC[hapus] == 1){
			echo"
			<a href='#' Onclick='Javascript:hapus2(\"cuti_tahunan\",\"$rowcuti[NIK]\",\"$rowcuti[id]\");'><img src='../images/b_delete.png' title='Delete' alt='Delete' border='0'>";
			}
			echo"</td>
			</tr>
			";
		  }
		  echo"
		 </table>
		</fieldset>
		";
	//////////////////////////// END CUTI TAHUNAN ////////////////////////
}
	//////////////////////////// BEGIN CUTI BESAR DAN KHUSUS ////////////////////////
elseif($HTTP_GET_VARS['jenis_cuti'] == "CB" || $HTTP_GET_VARS['jenis_cuti'] == "CK"){

	// untuk persetujuan cuti tahunan  
	if($HTTP_GET_VARS['appr'] == "yes" && $HTTP_GET_VARS['jenis_cuti'] == "CK"){
	$sql = mssql_query("UPDATE Cuti SET aktif='A' WHERE id='$no'",$conn);
	}

	if($HTTP_GET_VARS['appr'] == "yes" && $HTTP_GET_VARS['jenis_cuti'] == "CB"){
	$sql = mssql_query("UPDATE Cuti SET aktif='A' WHERE id='$no'",$conn);
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	  // get pengajuan cuti besar or khusus//////////////////////////////////////////////////
	  $qx		 = "SELECT count(*) FROM Cuti A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND C.AreaCode IN (";
		for($k=0;$k<count($VAreaCode);$k++){
			$qx .= "'$VAreaCode[$k]',";
		}
		
		$qx 	.= "'$VAreaCode[0]')";	
	  
	  // cek keyword
	  if(!empty($keyword)){
	  		$qx .= " AND (B.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%') ";
	  }
	  
	  if($HTTP_GET_VARS['jenis_cuti'] == "CB"){
	  		$qx .= " AND id_JenisCuti='2' ";
	  }
	  
	  if($HTTP_GET_VARS['jenis_cuti'] == "CK"){
	  		$qx .= " AND id_JenisCuti <> '2' ";
	  }

	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}

	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$qx .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
		 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$qx .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
		 elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$qx .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}
	
	  // cek divisi
	 if(!empty($HTTP_GET_VARS['divisi'])){
		$qx .= " AND (substring(B.kode_so1,1,7)='".substr($divisi,0,7)."' OR (substring(B.kode_so2,1,7)='".substr($divisi,0,7)."'))";
	 }
	 
	 // cek status
	 if(!empty($HTTP_GET_VARS['status'])){
	 	if($HTTP_GET_VARS['status'] == "A"){
			$qx .= " AND aktif='A'";
		}
		else{
			$qx .= "AND (aktif='P' OR aktif='T')";
		}
	 } 
	 else{
			$qx .= "AND (aktif='P' OR aktif='T')";
	 }
	  
	  //$qx		.= " ORDER BY tgl_awal DESC";
	  
	  $sqlcutix = mssql_query($qx,$conn);
		
	//$result	= mssql_query("SELECT count(*) FROM Karyawan",$conn);
	$total	= mssql_fetch_row($sqlcutix);
	$limit	= 15;
	$pager  = Pager::getPagerData($total[0], $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;
	
	PagingMedCut($pager,$page,$next,$limit,$keyword,$show,$conn,$status,$divisi,$bulan1,$bulan2,$tahun1,$tahun2,$jenis_cuti);
		
		if($HTTP_GET_VARS['jenis_cuti'] == "CB"){
			$CTitle = "CUTI BESAR";
		}
		elseif($HTTP_GET_VARS['jenis_cuti'] == "CK"){
			$CTitle = "CUTI KHUSUS";
		}
		
		echo"
		<fieldset>
		 <legend><b>Daftar Pengajuan $CTitle</b></legend>
		 <table width='100%'>
		  <tr class=headlist>
		   <td>No</td>
		   <td>Tgl Mulai</td>
		   <td>Tgl Selesai</td>
		   <td>Jml Cuti</td>
		   <td>NIK</td>
		   <td>Nama</td>
		   <td>Divisi/Biro/Unit Kerja</td>";
		if($HTTP_GET_VARS['jenis_cuti'] == "CB"){
		   echo"
		   <td>Periode</td>
		   <td>Sisa Cuti</td>";
		}
		   echo"
		   <td>Keterangan</td>
		   <td>&nbsp;</td>
		  </tr>";
		  
	  // get pengajuan cuti besar/khusus
	  $sqlcutixy = "WITH ASDF AS (SELECT ROW_NUMBER() OVER(ORDER BY tgl_awal DESC) No, CONVERT(CHAR(12), tgl_awal, 103) Tgl, CONVERT(CHAR(12), tgl_akhir, 103) TglAkhir, A.*,B.Nama,B.kode_so2 FROM Cuti A, VLatestKarir B, MstSO C WHERE A.NIK=B.NIK AND B.kode_so2=C.kode_so AND C.AreaCode IN (";

		for($k=0;$k<count($VAreaCode);$k++){
			$sqlcutixy .= "'$VAreaCode[$k]',";
		}
		
		$sqlcutixy 	.= "'$VAreaCode[0]')";	
	  
	  // cek keyword
	  if(!empty($keyword)){
	  		$sqlcutixy .= " AND (B.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%') ";
	  }
	  
	  if($HTTP_GET_VARS['jenis_cuti'] == "CB"){
	  		$sqlcutixy .= " AND id_JenisCuti='2' ";
	  }
	  
	  if($HTTP_GET_VARS['jenis_cuti'] == "CK"){
	  		$sqlcutixy .= " AND id_JenisCuti <> '2' ";
	  }

	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}

	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$sqlcutixy .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
		 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$sqlcutixy .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
		 elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$sqlcutixy .= " and tgl_awal between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}

	  // cek divisi
	 if(!empty($HTTP_GET_VARS['divisi'])){
		$sqlcutixy .= " AND ((substring(kode_so2,1,7)='".substr($divisi,0,7)."'))";
	 }
	 
	 // cek status
	 if(!empty($HTTP_GET_VARS['status'])){
	 	if($HTTP_GET_VARS['status'] == "A"){
			$sqlcutixy .= " AND aktif='A'";
		}
		else{
			$sqlcutixy .= "AND (aktif='P' OR aktif='T')";
		}
	 } 
	 else{
			$sqlcutixy .= "AND (aktif='P' OR aktif='T')";
	 }

	$sqlcutixy .= ") SELECT * FROM ASDF WHERE No BETWEEN $offset AND ".($offset+$limit)."";	  
	$sqlcutixy .= " ORDER BY tgl_awal DESC";
	  
	
	  $sqlcuti = mssql_query($sqlcutixy,$conn);
		  while($rowcuti = mssql_fetch_array($sqlcuti)){
		  	echo"
			<tr class=contentlist>
			 <td align=right>$rowcuti[No]</td>
			 <td>$rowcuti[Tgl]</td>
			 <td>$rowcuti[TglAkhir]</td>
			 <td align=center>$rowcuti[jml_cuti]</td>
			 <td>$rowcuti[NIK]</td>
			 <td>$rowcuti[Nama]</td>";
			 
			$kodeso = $rowcuti[kode_so2];
			
			if(empty($kodeso)){
			}
			else{
				$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
				if(mssql_num_rows($s1) > 0){
					$r1 = mssql_fetch_array($s1);
					if(!empty($r1[uraian])){
						echo"<td style='font-size:8px;'>$r1[uraian]</td>";
					}
					else{
						echo"<td>&nbsp;</td>";
					}			
				}
				else{
						echo"<td>&nbsp;</td>";
				}
			}	
		
		if($HTTP_GET_VARS['jenis_cuti'] == "CB"){
			echo"
			 <td style='font-size:9px;' align=center>$rowcuti[periode]</td>
			 <td align=center>";
			////////////////// get sisa cuti  
            // get jatah cuti besar
            $gj = mssql_query("SELECT jatah_cuti, syarat_waktu FROM VJCuti WHERE nama='Cuti Besar'",$conn);
            $rj = mssql_fetch_array($gj);
            $jatah_cuti = $rj[jatah_cuti];
            $syarat_cuti= $rj[syarat_waktu];
			// sisa cuti
			$sqlsisa 	= mssql_query("SELECT count(*) jumlah FROM Cuti WHERE NIK='$rowcuti[NIK]' AND periode='$rowcuti[periode]' AND aktif IN ('A',NULL)",$conn);
			$cntsisa 	= mssql_fetch_array($sqlsisa);
			$sisa_cuti	= $jatah_cuti - $cntsisa[jumlah];
			
			echo"$sisa_cuti</td>";
		}
			echo"<td>";
			 if($rowcuti[aktif] == "A"){
			 	echo"Disetujui";
			 }
			 elseif($rowcuti[aktif] == "T"){
			 	echo"<span style='color: red;'>(<b>Pengajuan Ambil Tunda Cuti</b>)</span>";
			 }
			 else{
			 	if($rowcuti[tunda] == 1){
				 	echo"<span style='color: red;'>(<b>Pengajuan Tunda Cuti</b>)</span>";
				}
				else{
				// get nama jenis cuti
				$sgj = mssql_query("SELECT nama FROM VJCuti WHERE kode_cuti='$rowcuti[id_JenisCuti]'",$conn);
				$rgj = mssql_fetch_array($sgj);
				 	echo"<span style='color: red;'>(<b>$rgj[nama]</b>)</span>";
				}
			 }
			echo"</td>";
			if($HTTP_GET_VARS['jenis_cuti'] == "CK"){
				$CKCB1 = "khusus";
				$CKCB2 = "cuti_khusus";
			}
			elseif($HTTP_GET_VARS['jenis_cuti'] == "CB"){
				$CKCB1 = "besar";
				$CKCB2 = "cuti_besar";
			}
			echo"
			<td><a href='../report/rep_cuti.php?nik=$rowcuti[NIK]&amp;cuti=$CKCB1&amp;no=$rowcuti[id]&amp;periode=".$pert."' target='_blank'><img src='../images/fileprint.png' title='Cetak Surat Permohonan' alt='Cetak Surat Permohonan' border=0></a>";
			// approval
			if($rparC[approval] == 1){
			echo"
			<a href='#' Onclick='Javascript:appr_CBCK(\"cuti\",\"$rowcuti[id]\",\"".$HTTP_GET_VARS['jenis_cuti']."\");'><img src='../images/apply.png' title='Approval/\Persetujuan' alt='Approval/\Persetujuan' border=0></a>";
			}
			// edit
			if($rparC[edit] == 1){
			echo"
			<a href='../form/frm_emp_cuti.php?show=$CKCB2&amp;op=edit&amp;nik=$rowcuti[NIK]&amp;no=$rowcuti[id]'><img src='../images/b_edit.png' title='Edit' alt='Edit' border=0></a>";
			}
			//hapus
			if($rparC[hapus] == 1){
			echo"
			<a href='#' Onclick='Javascript:hapus2(\"$CKCB2\",\"$rowcuti[NIK]\",\"$rowcuti[id]\");'><img src='../images/b_delete.png' title='Delete' alt='Delete' border='0'>";
			}
			echo"</td>
			</tr>
			";
		  }
		  echo"
		 </table>
		</fieldset>
		";
	//////////////////////////// END CUTI BESAR ////////////////////////
}
	echo'
		  </td>
		 </tr>
		</table>
	';
}
// untuk PENCARIAN MEDICAL
elseif($show == "medical"){	
?>
<script type="application/javascript">
	function hapusM(ID)
	{
		var ok = confirm("Apakah Anda yakin menghapus data tersebut ?");
		if(ok == true)
		{
			window.location.href="<?=$PHP_SELF?>?show=medical&delete=yes&id="+ID+"";
		}
		else
		{
		}
	}
</script>
<?
// untuk delete saja
if($HTTP_GET_VARS['delete'] == "yes"){
	$sqlD = mssql_query("DELETE FROM MedicalRestitusiDetail WHERE nomor='".$HTTP_GET_VARS['id']."'",$conn);
}

// cek hak akses (privileges)
$shmed = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='medical' AND hapus='1'",$conn);
$rhmed = mssql_num_rows($shmed);
//////////////////////////////////////

	/*
	MA = Kode Mata Anggaran
	RJ = Rawat Jalan
	RI = Rawat Inap
	KC = Kacamata
	PR = Persalinan
	*/
	switch($jenis){
		case "RJ":
			$MA = " AND C.mata_anggaran IN ('811101','811103','811199') ";
			break;
		case "RI":
			$MA = " AND C.mata_anggaran IN ('811102') ";
			break;
		case "KC":
			$MA = " AND C.mata_anggaran IN ('811104') ";
			break;
		case "PR":
			$MA = " AND C.mata_anggaran IN ('811106') ";
			break;
			
		default: $MA = " AND mata_anggaran IN ('811101','811103','811199') ";
	}
	
	echo"
		<table width=100% class='table_indent2' border='0'>
		 <tr>
		  <td colspan=2 class=line_bottom>&nbsp;&nbsp;<b>MEDICAL KARYAWAN</b> | <a href='$PHP_SELF?show=setup_medical'>PLAFON MEDICAL</a></td>
		 </tr>
		 <tr>
		  <td colspan=2 align=left>";
		  $bulan1 = $HTTP_GET_VARS['bulan1'];
		  $bulan2 = $HTTP_GET_VARS['bulan2'];
		  $tahun1 = $HTTP_GET_VARS['tahun1'];
		  $tahun2 = $HTTP_GET_VARS['tahun2'];
		  $divisi = $HTTP_GET_VARS['divisi'];

		 SearchMedical($conn,$bulan1,$bulan2,$tahun1,$tahun2,$divisi,$jenis);

	$sql	= "SELECT ROW_NUMBER() OVER (ORDER BY TGL DESC) AS No, CONVERT(CHAR(12), TGL, 103) Tanggal, NMR nomor, A.* FROM VListUpMedical A, VLatestKarir B, MedicalRestitusiDetail C, MstSO D WHERE A.NMR=C.nomor AND B.NIK=C.NIK AND B.kode_so2=D.kode_so  ".$MA." AND D.AreaCode IN (";
	for($k=0;$k<count($VAreaCode);$k++){
		$sql .= "'$VAreaCode[$k]',";
	}
	
	$sql 	.= "'$VAreaCode[0]')";	

	 if(!empty($keyword)){
		$sql .= " AND (B.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%') ";
	 }

/* BULAN TAHUN PERIODE		
	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}

	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$sql .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
	 	 
		 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$sql .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
		 elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$sql .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}
*/		
		 if(!empty($status)){
			$sql .= " AND A.status='$status'";
		 }
		
		 if(!empty($HTTP_GET_VARS['awal']) && !empty($HTTP_GET_VARS['akhir'])){
		 	$sql .= " AND tanggal BETWEEN '".$HTTP_GET_VARS['awal']."' AND '".$HTTP_GET_VARS['akhir']."' ";
		 }	
		 
		 if(!empty($HTTP_GET_VARS['divisi'])){
		 	$sql .= " AND substring(kode_so2,1,7)='".substr($divisi,0,7)."'";
		 }
	
	//echo $sql;
			
	$result	= mssql_query($sql,$conn);
	$total	= mssql_num_rows($result);
	$limit	= 15;
	$pager  = Pager::getPagerData($total, $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;	
	
	// get data medical terbaru
	//PagingMedCut($pager,$page,$next,$limit,$keyword,$show,$conn,$status,$divisi,$bulan1,$bulan2,$tahun1,$tahun2,$jenis_cuti);
	PagingMedSaja($pager,$page,$next,$limit,$keyword,$show,$conn,$status,$divisi,$jenis,$awal,$akhir,$jenis_cuti);
	//$sqlmedc = "WITH DDD AS (SELECT ROW_NUMBER() OVER (ORDER BY B.Tanggal DESC) AS No, C.NIK, C.Nama, B.tanggal, B.nomor, C.kode_so1, C.kode_so2 from VListUpMedical A, MedicalRestitusiDetail B, VLatestkarir C WHERE A.NMR=B.nomor AND B.NIK=C.NIK ";
	$sqlmedc	= "WITH DDD AS (SELECT ROW_NUMBER() OVER (ORDER BY TGL DESC) AS No, CONVERT(CHAR(12), TGL, 103) Tanggal, NMR nomor, A.* FROM VListUpMedical A, VLatestKarir B, MedicalRestitusiDetail C, MstSO D WHERE A.NMR=C.nomor AND B.NIK=C.NIK AND B.kode_so2=D.kode_so ".$MA." AND D.AreaCode IN (";

	for($k=0;$k<count($VAreaCode);$k++){
		$sqlmedc .= "'$VAreaCode[$k]',";
	}
	
	$sqlmedc 	.= "'$VAreaCode[0]') ";	
	
	if(!empty($keyword)){
		$sqlmedc .= " AND (B.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%')";
	}

/* BULAN TAHUN PERIODE
	if($HTTP_GET_VARS['bulan2']+1 == 13){
		$bulanke2 = "01";
	}
	else{
		$bulanke2 = ($HTTP_GET_VARS['bulan2']+1);
	}

	if($HTTP_GET_VARS['bulan1']+1 == 13){
		$bulanke1 = "01";
	}
	else{
		$bulanke1 = ($HTTP_GET_VARS['bulan1']+1);
	}

	  // cek bulan dan tahun
	 if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && !empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2'])){
		$sqlmedc .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."')";
	 }
	 else{	
	 	 
	if(!empty($HTTP_GET_VARS['bulan1']) && !empty($HTTP_GET_VARS['tahun1']) && empty($HTTP_GET_VARS['bulan2']) && empty($HTTP_GET_VARS['tahun2'])){
			$sqlmedc .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan1']."/01/".$HTTP_GET_VARS['tahun1']."') and convert(datetime,'".$bulanke1."/01/".$HTTP_GET_VARS['tahun1']."') ";
		 }
	elseif(!empty($HTTP_GET_VARS['bulan2']) && !empty($HTTP_GET_VARS['tahun2']) && empty($HTTP_GET_VARS['bulan1']) && empty($HTTP_GET_VARS['tahun1'])){
			$sqlmedc .= " and tanggal between convert(datetime,'".$HTTP_GET_VARS['bulan2']."/01/".$HTTP_GET_VARS['tahun2']."') and convert(datetime,'".$bulanke2."/01/".$HTTP_GET_VARS['tahun2']."') ";
		 }	
	}
*/

	if(!empty($status)){
		$sqlmedc .= " AND A.status='$status'";
	}

	if(!empty($HTTP_GET_VARS['awal']) && !empty($HTTP_GET_VARS['akhir'])){
		$sqlmedc .= " AND tanggal BETWEEN '".$HTTP_GET_VARS['awal']."' AND '".$HTTP_GET_VARS['akhir']."' ";
	}	

	if(!empty($status)){
		$sqlmedc .= " AND A.status='$status' ";
	}

	if(!empty($HTTP_GET_VARS['divisi'])){
	$sqlmedc .= " AND substring(kode_so2,1,7)='".substr($divisi,0,7)."'";
	}
	else{
	}

	$sqlmedc .= ") SELECT CONVERT(CHAR(12), tanggal, 103) Tanggal, nomor FROM DDD WHERE No BETWEEN $offset AND ".($offset+$limit)." GROUP BY nomor,Tanggal";

	$sqlmed = mssql_query($sqlmedc,$conn);
		  echo"</td>
		 </tr>
		 <tr>
		  <td>
		  <fieldset>
		  <legend>Daftar Pengajuan</legend>
		  <table width=100%>";
		  if(mssql_num_rows($sqlmed) > 0){
		  echo"
		   <tr class=headlist>
		    <!--<td width=25 align='right'>No.</td>-->
			<td width=75>Tanggal</td>
			<!--<td width=100>No. Restitusi</td>-->
			<td width=100>NIK</td>
			<td>Nama</td>
			<td>Divisi/Biro/Unit Kerja</td>
			<td>Jenis</td>
			<td>Status</td>
			<td>&nbsp;</td>
		   </tr>";
		  while($rowmed = mssql_fetch_array($sqlmed)){
			echo"
			<tR class=contentlist>
			 <!--<td align='right'>$rowmed[No]</td>-->
			 <td>$rowmed[Tanggal]</td>
			 <!--<td width=120>$rowmed[nomor]</td>-->";
			 // get nik dan divisi
			 $slate = mssql_query("SELECT * FROM VLatestKarir A, MedicalRestitusiDetail B WHERE A.NIK=B.NIK AND B.nomor='$rowmed[nomor]'",$conn);
			 $rlate = mssql_fetch_array($slate);
			 echo"
			  <td><a href='../form/frm_emp_medical.php?nikg=$rlate[NIK]&amp;no_res=$rowmed[nomor]&amp;st=setuju'>$rlate[NIK]</a></td>
			  <td><a href='../form/frm_emp_medical.php?nikg=$rlate[NIK]&amp;no_res=$rowmed[nomor]&amp;st=setuju'>$rlate[Nama]</td>
			 ";
		//if(empty($rlate[kode_so1])){
			$kodeso = $rlate[kode_so2];
		//}
		//else{
			//$kodeso = $rlate[kode_so1];
		//}
		
		if(empty($kodeso)){
			//echo"<td>&nbsp;</td>";
			echo"<td style='width: 250px;'>&nbsp;</td>";
		}
		else{
			$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
			if(mssql_num_rows($s1) > 0){
				$r1 = mssql_fetch_array($s1);
				if(!empty($r1[uraian])){
					echo"<td style='width: 250px;'><small><a href='../form/frm_emp_medical.php?nikg=$rlate[NIK]&amp;no_res=$rowmed[nomor]&amp;st=setuju'>$r1[uraian]</td>";
				}
				else{
					echo"<td style='width: 250px;'>&nbsp;</td>";
				}			
			}
			else{
				echo"<td style='width: 250px;'>&nbsp;</td>";
			}
		}	
	
			// jenis
			echo"<td style='color: blue;'><small>";
			switch($rlate[mata_anggaran]){
				case "811101":
					echo"Rawat Jalan";
					break;
				case "811103":
					echo"Rawat Jalan";
					break;
				case "811199":
					echo"Rawat Jalan";
					break;
				case "811102":
					echo"Rawat Inap";
					break;
				case "811104":
					echo"Kaca Mata";
					break;
				case "811106":
					echo"Persalinan";
					break;
			}
			echo"</td>";
			echo" 
			 <td>";
			if($rlate[status] == "A"){
				echo"<a href='../form/frm_emp_medical.php?nikg=$rlate[NIK]&amp;no_res=$rowmed[nomor]&amp;st=setuju'>Disetujui";
			}
			else{
				echo"<a href='../form/frm_emp_medical.php?nikg=$rlate[NIK]&amp;no_res=$rowmed[nomor]&amp;st=setuju'><span style='color:red;'>Sedang diproses</span>";
			}
			// tombol untuk detail
			echo"</td>
			<td><a href='listmedical.php?show=historical&amp;nik=$rlate[NIK]' target='_blank'><img src='../images/detail.png' border='0' title='Detil Medical Pegawai' alt='Detil Medical Pegawai'></a>";
			// tombol untuk delete data
			if($rhmed > 0){
				echo"&nbsp;<a href='#' onclick=\"hapusM('$rowmed[nomor]')\"><img src='../images/b_delete.png' border='0'></a>";
			}
			echo"</td>
			</tR>
			";
			}
		  }
		  else{
		  	echo"
			<tr>
			 <td colspan=8 align=center style='color:red;'>-- Pencarian Tidak ditemukan --</td>
			</tr>";
		  }
		  echo"
		  </table>
		  </fieldset>
		  </td>
		 </tr>
		</table>";
	echo'	
	 	  </td>
	  	 </tr>
	    </table>
	   </td>  
	   </tr>';
	echo'</table>';
}
// untuk PENCARIAN SETUP_MEDICAL
elseif($show == "setup_medical"){
	$bulan1 = $HTTP_GET_VARS['bulan1'];
	$bulan2 = $HTTP_GET_VARS['bulan2'];
	$tahun1 = $HTTP_GET_VARS['tahun1'];
	$tahun2 = $HTTP_GET_VARS['tahun2'];
	$divisi = $HTTP_GET_VARS['divisi'];
	 // untuk hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='setup_medical'",$conn);
	$rpar = mssql_fetch_array($spar);	

	echo"
		<table width=93% class='table_indent2'>
		<tr height=10>
		 <td></td>
		</tr>
		 <tr>
		  <td colspan=2 align=left>";
	SearchPlafonMedical($conn,$bulan1,$bulan2,$tahun1,$tahun2,$divisi);
	echo"
		  </td>
		 </tr>
		 <tr>
		  <td colspan=2>";
		  if($rpar[tambah] == 1){
		  echo"<input type=button value=\"Tambah\" class=\"button\" onclick=Javascript:location.href=\"../form/frm_emp_plafon.php?show=plafon_awal\">";
		  }
		  echo"
		  </td>
		 </tr>";
		 
		$sqlnums = "WITH SDF AS (SELECT A.NIK,A.Nama FROM VSetupMedical A, VLatestKarir B, MstSO C WHERE B.kode_so2=C.kode_so AND A.NIK=B.NIK AND (A.NIK LIKE '%$keyword%' OR B.Nama LIKE '%$keyword%') AND C.AreaCode IN (";
		 
		for($k=0;$k<count($VAreaCode);$k++){
			$sqlnums .= "'$VAreaCode[$k]',";
		}
		
		$sqlnums 	.= "'$VAreaCode[0]')";	
		 
		if(!empty($divisi)){
			$sqlnums .= " AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."') ";
		}
		
		if(!empty($tahun1)){
			$sqlnums .= " AND Periode ='".$tahun1."' ";
		}
		 
		$sqlnums .= "GROUP BY A.NIK,A.Nama) SELECT * FROM SDF";
		 
		$sql_num 	= mssql_query($sqlnums,$conn);
		//$cnt_num	= mssql_num_rows($sql_num);	
		
		$total	= mssql_num_rows($sql_num);
		$limit	= 15;
		$pager  = Pager::getPagerData($total, $limit, $page);
		$offset = $pager->offset;
		$limit  = $pager->limit;
		$page   = $pager->page;

		if($total > 0){
		echo"
		<tr>
		 <td colspan=3>";
		Paging3($pager,$page,$next,$limit,$keyword,$show,$divisi,$tahun1);
		echo"</td>
		</tr>
		";
		 echo"<tr>
		  <td colspan=2>
		   <table width=100%>
		    <tr class=headlist>
			 <td width=1%>No</td>
			 <td width=80>NIK</td>
			 <td>Nama</td>
			 <td>Divisi/Biro/Unit Kerja</td>
			</tr>";

			$sqlxxx = "WITH AJX AS (SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, A.NIK, A.Nama FROM VLatestKarir A, VSetupMedical B, MstSO C WHERE A.kode_so2=C.kode_so AND (A.NIK LIKE '%$keyword%' OR A.Nama LIKE '%$keyword%') AND A.NIK=B.NIK AND C.AreaCode IN (";
						
			for($k=0;$k<count($VAreaCode);$k++){
				$sqlxxx .= "'$VAreaCode[$k]',";
			}
			
			$sqlxxx 	.= "'$VAreaCode[0]')";	

			if(!empty($divisi)){
				$sqlxxx .= " AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."') ";
			}
			
			if(!empty($tahun1)){
				$sqlxxx .= " AND Periode ='".$tahun1."' ";
			}
			
			$sqlxxx .= " GROUP BY A.NIK,A.Nama ) SELECT * FROM AJX WHERE No BETWEEN $offset AND ".($offset+$limit)."";
			
			$sql = mssql_query($sqlxxx,$conn);
			if(mssql_num_rows($sql) > 0){
			while($row = mssql_fetch_array($sql)){
			  echo"<tr class=contentlist>
				 <td class=contentlist align='right'><a href='listmedical.php?show=setup_medical&amp;nik=$row[NIK]'>$row[No]</a></td>
				 <td class=contentlist><a href='listmedical.php?show=setup_medical&amp;nik=$row[NIK]'>$row[NIK]</a></td>
				 <td class=contentlist><a href='listmedical.php?show=setup_medical&amp;nik=$row[NIK]'>$row[Nama]</a></td>";
			 // get nik dan divisi
			 $slate = mssql_query("SELECT * FROM VLatestKarir A, VSetupMedical B WHERE A.NIK=B.NIK AND A.NIK='$row[NIK]'",$conn);
			 $rlate = mssql_fetch_array($slate);
				 
			if(empty($rlate[kode_so1])){
				$kodeso = $rlate[kode_so2];
			}
			else{
				$kodeso = $rlate[kode_so1];
			}
			
			if(empty($kodeso)){
				//echo"<td>&nbsp;</td>";
				//echo"<td>&nbsp;</td>";
			}
			else{
				$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
				if(mssql_num_rows($s1) > 0){
					$r1 = mssql_fetch_array($s1);
					if(!empty($r1[uraian])){
						echo"<td><a href='listmedical.php?show=setup_medical&amp;nik=$row[NIK]'>$r1[uraian]</td>";
					}
					else{
					}			
				}
				else{
				}
			}				 
				 
			  echo"</tr>";
			}
			}
			else{
			echo"
			<tr>
			 <td colspan=10 align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			}
		}
		else{
			echo"
			<tr>
			 <td colspan=10 align=center style='color:red; text-indent:50px;'><b>Maaf, Pencarian tidak ditemukan ...</b></td>
			</tr>
			";
			//exit();
		}
	   echo'</table>
		  </td>
		 </tr>
		</table>
	';
}

?>
</td>
 </tr>
</table>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>